<template>
	<mescroll-uni :ref="'mescrollRef'+i" @init="mescrollInit" @down="downCallback"
		@up="upCallback">
		<view style="padding: 0 30rpx;">
			<view
			v-for="(item, index) in dataList"
			:key="index"
			class="u-p-t-36"
			@click="jumpUrl(`/pages/user/personal/index/index?userId=${ item.userId }`)">
				<view class="flex-center">
					<view class="u-avatar-60 clear-flex" style="width: 110rpx; height: 110rpx;" @click.stop>
						<x-image :src="showImage(item.avatar, 'logo')" preview/>
					</view>
					<view class="flex-between flex-column" style="padding: 12rpx 18rpx;">
						<view>{{ item.nick || '' }}</view>
						<view class="flex-center color-grew u-f-28 u-lh-40">
							<view class="u-m-r-30">{{ lang_common.fans }}{{ item.fansCount || 0 }}</view>
							<view>{{ lang_common.follow }}{{ item.followCount || 0 }}</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</mescroll-uni>
</template>

<script>
	import { userFollowPage, userFansPage } from '@/api/personal.js'
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	import MescrollMoreItemMixin from "@/components/mescroll-uni/mixins/mescroll-more-item.js";

	export default {
		mixins: [MescrollMixin, MescrollMoreItemMixin], // 注意此处还需使用MescrollMoreItemMixin (必须写在MescrollMixin后面)
		props: {
			i: Number, // 每个tab页的专属下标 (除了支付宝小程序必须在这里定义, 其他平台都可不用写, 因为已在MescrollMoreItemMixin定义)
			index: { // 当前tab的下标 (除了支付宝小程序必须在这里定义, 其他平台都可不用写, 因为已在MescrollMoreItemMixin定义)
				type: Number,
				default () {
					return 0
				}
			},
			userId: {
				default: ''
			}
		},
		data() {
			return {
				dataList: []
			}
		},
		watch: {
			userId(v) {
				if (v) {
					this.downCallback()
				}
			}
		},
		methods: {
			getList(obj) {
				if (this.i === 0) {
					return userFollowPage(obj)
				} else if(this.i === 1) {
					return userFansPage(obj)
				}
			},
			/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
			upCallback(page) {
				let node = this.$refs['mescrollRef' + this.i]
				if (!this.userId) return node && node.mescroll.endSuccess(0)
				this.getList({
					pageNumber: page.num,
					pageSize: page.size,
					userId: this.userId,
				}).then(res => {
					node && node.mescroll.endSuccess(res.list.length);
					if (page.num == 1) this.dataList = []; //如果是第一页需手动制空列表
					this.dataList = this.dataList.concat(res.list); //追加新数据
					this.$emit('change', ({ index: this.i, number: res.totalRow }))
				}).catch(() => {
					node && node.mescroll.endErr();
				})
			},
			downCallback() {
				let node = this.$refs['mescrollRef' + this.i]
				node && node.mescroll.resetUpScroll()
			},
		}
	}
</script>
